jQuery(document).ready(function() { 
    jQuery(".upload_img_button").live("click", function(event){
      event.preventDefault();
          var ImgUploadID = jQuery(this).attr('id');
          tb_show('', 'media-upload.php?type=image&amp;TB_iframe=true');
          window.send_to_editor = function(html) {
                var imgurl = jQuery('img',html).attr('src');
                if(imgurl){
                    jQuery('#'+ImgUploadID).val(imgurl);
                }else{
                    var fileurl = jQuery(html);
                    var fName = jQuery(fileurl).attr('href');
                    jQuery('#'+ImgUploadID).val(fName);
                }
                tb_remove();
          }
    });
    
    jQuery('#add_custom_content_image').click(function(){
        
	    var num_count = 0;
        num_count = jQuery('#media_meta_table1 tbody tr').length;
        var content___ = '';
        
    content___ += '<tr>';
        content___ += '<td>';
        content___ += '<label>Image :</label>';
        content___ += '</td>';
        content___ += '<td>';
        content___ += '<input type="text" name="_media_meta[media_meta_data1]['+(num_count)+'][link]" value="" id="_media_meta_'+(num_count)+'" size="50%" />';
        content___ += '<input type="hidden" name="_media_meta[media_meta_data1]['+(num_count)+'][mediatype]" value="image"/>';
        content___ += '</td>';
        content___ += '<td>';
        content___ += '<input class="upload_img_button"  id="_media_meta_'+(num_count)+'" type="button" value="Upload Image" />';
        content___ += '</td>';
        content___ += '<td>';
        content___ += '<input class="delete_img_button" type="button" value="Delete" onClick="jQuery(this).parent().parent().remove();"/>';
        content___ += '</td>';
      content___ += '</tr>';
    jQuery('#media_meta_table1').append(content___);
    });

    jQuery('#add_custom_content_video').click(function(){
	    var num_count = 0;
        num_count = jQuery('#media_meta_table1 tbody tr').length;
        var content___ = '';

            content___ += '<tr>';
            content___ += '<td>';
            content___ += '<label>Video :</label>';
            content___ += '</td>';
            content___ += '<td>';
            content___ += '<input type="text" name="_media_meta[media_meta_data1]['+(num_count)+'][link]" value="" id="_media_meta_'+(num_count)+'" size="50%" />';
            content___ += '<input type="hidden" name="_media_meta[media_meta_data1]['+(num_count)+'][mediatype]" value="video"/>';
            content___ += '</td>';
            content___ += '<td>';
            content___ += '<input class="upload_img_button"  id="_media_meta_'+(num_count)+'" type="button" value="Upload Video" />';
            content___ += '</td>';
            content___ += '<td>';
            content___ += '<input class="delete_img_button" type="button" value="Delete" onClick="jQuery(this).parent().parent().remove();"/>';
            content___ += '</td>';
            content___ += '</tr>';
        jQuery('#media_meta_table1').append(content___);
    });
  

});